/**
 * Created by ZhouWei on 2017/6/17.
 */


$(function () {
    windowChange();
    getStorage();
    $(window).resize(function() {
        windowChange();
    });
    $('form').submit(function() {
        var data = $(this).serialize();
        var userName = $("input[name='userName']").val();
        var userPwd = $("input[name='userPwd']").val();
        var checkPwd = $("input[name='checkPwd']").is(':checked');
        if(!userName || !userPwd){
            $('.report').html('用户名或密码不能为空').slideDown(500);
            setTimeout(function(){
                $('.report').slideUp(500);
            },2000)
        }else {
            if(!(/^1[34578]\d{9}$/.test(userName))){
                $('.report').html("手机号码有误，请重新输入").slideDown(500);
                setTimeout(function(){
                    $('.report').slideUp(500);
                },2000);
                return false;
            }else if (!(/^[0-9]{6,16}$/.test(userPwd))){
                $('.report').html("密码长度有误，请重新输入").slideDown(500);
                setTimeout(function(){
                    $('.report').slideUp(500);
                },2000);
                return false;
            }else{
                //下面这个应该放到ajax成功的返回函数中去 不然有可能会保存一些错误的信息
                if(checkPwd){
                    localStorage.setItem("userName",userName);
                    localStorage.setItem("userPwd",userPwd);
                }else{
                    localStorage.setItem("userName","");
                    localStorage.setItem("userPwd","");
                }
                $("#screen").fadeIn(1000);
                //ajax
            }
        }
        return false;
    });
    $("#register").click(function(){
        window.location.href = "./register.html"
    })
});


function getStorage(){
    var userName = localStorage.getItem("userName");
    var userPwd = localStorage.getItem("userPwd");
    if(userName && userPwd){
        $("input[name='userName']").val(userName);
        $("input[name='userPwd']").val(userPwd);
    }
}

function windowChange(){
    if($(window).height()>1080){
        $('.formInformation').css("margin","50px auto").addClass("input-group-lg");
        $('.formButton').css("margin","50px auto").addClass("btn-lg");
        var wH = $(window).height();
        var mH = parseInt( $('.main').css('height'));
        var mT = (wH-mH*2)/2 + "px";
        $('.main').css('marginTop',mT);
        $("body").css("zoom",1.5);
    }else if($(window).height()<700){
        $("body").css("zoom",1);
        $('.formInformation').css("margin","15px auto");
        $('.formButton').css("margin","15px auto");
        var wH = $(window).height();
        var mH = parseInt( $('.main').css('height'));
        var mT = (wH-mH)/2-10 + "px";
        $('.main').css('marginTop',mT);
    }else{
        $("body").css("zoom",1);
        $('.main').css('marginTop',"50px");
        $('.formInformation').css("margin","20px auto").removeClass("input-group-lg");
        $('.formButton').css("margin","20px auto").removeClass("btn-lg");
    }
}













